home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
frasr182.zip
/
JIIM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-31
|
37KB
|
1,551 lines
/*
* JIIM.C
*
* Generates Inverse Julia in real time, lets move a cursor which determines
* the J-set.
*
* The J-set is generated in a fixed-size window, a third of the screen.
*
* This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
*
*
* The routines used to set/move the cursor and to save/restore the
* window were "borrowed" from editpal.c (TW - now we *use* the editpal code)
* (if you don't know how to write good code, look for someone who does)
*
* JJB [jbuhler@gidef.edu.ar]
* TIW Tim Wegner
* MS Michael Snyder
* KS Ken Shirriff
* Revision History:
*
* 7-28-92 JJB Initial release out of editpal.c
* 7-29-92 JJB Added SaveRect() & RestoreRect() - now the
* screen is restored after leaving.
* 7-30-92 JJB Now, if the cursor goes into the window, the
* window is moved to the other side of the screen.
* Worked from the first time!
* 10-09-92 TIW A major rewrite that merged cut routines duplicated
* in EDITPAL.C and added orbits feature.
* 11-02-92 KS Made cursor blink
* 11-18-92 MS Altered Inverse Julia to use MIIM method.
* 11-25-92 MS Modified MIIM support routines to better be
* shared with stand-alone inverse julia in
* LORENZ.C, and to use DISKVID for swap space.
* 05-05-93 TIW Boy this change file really got out of date.
* Added orbits capability, various commands, some
* of Dan Farmer's ideas like circles and lines
* connecting orbits points.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef XFRACT
#include <stdarg.h>
#include <dos.h> /* for FP_SEG & FP_OFF */
#else
#include <varargs.h>
#endif
#include <math.h>
#ifdef __TURBOC__
# include <mem.h> /* to get mem...() declarations */
#endif
#include "helpdefs.h"
#include "fractint.h" /* for overlay stuff */
#include "fractype.h"
#include "prototyp.h"
#define FAR_RESERVE 8192L /* amount of far mem we will leave avail. */
#define MAXRECT 1024 /* largest width of SaveRect/RestoreRect */
#define newx(size) mem_alloc(size)
#define delete(block)
enum stored_at_values
{
NOWHERE,
DISK,
MEMORY
} ;
/* borrowed from LORENZ.C */
struct affine
{
/* weird order so a,b,e and c,d,f are vectors */
double a;
double b;
double e;
double c;
double d;
double f;
};
extern int setup_convert_to_screen(struct affine *);
int show_numbers =0; /* toggle for display of coords */
int stored_at;
char far *memory = NULL; /* pointer to saved rectangle */
FILE *file;
int windows = 0; /* windows management system */
extern char scrnfile[]; /* file where screen portion is */
/* stored */
extern BYTE *line_buff; /* must be alloced!!! */
extern int sxdots; /* width of physical screen */
extern int sydots; /* depth of physical screen */
extern int sxoffs; /* start of logical screen */
extern int syoffs; /* start of logical screen */
extern int strlocn[]; /* 10K buffer to store classes in */
extern int colors; /* # colors avail. */
extern int using_jiim;
extern int viewwindow; /* 0 for full screen, 1 for window */
extern float viewreduction; /* window auto-sizing */
extern int viewcrop; /* nonzero to crop default coords */
extern float finalaspectratio; /* for view shape and rotation */
extern int viewxdots,viewydots; /* explicit view sizing */
extern double dxsize, dysize;
extern int xdots; /* width of logical screen */
extern int ydots; /* depth of logical screen */
extern double xxmax,xxmin; /* limits of the "window" */
extern double yymax,yymin; /* on the z-plane */
extern int color_bright; /* brightest color in palette */
extern int color_dark; /* darkest color in palette */
extern int color_medium; /* nearest to medbright gray color */
extern int lookatmouse; /* mouse mode for getakey(), etc */
extern int maxit; /* try this many iterations */
extern int fractype; /* fractal type */
extern _CMPLX old,new,init;
extern double tempsqrx,tempsqry;
static int xc, yc; /* corners of the window */
static int xd, yd; /* dots in the window */
extern void displayc(int x, int y, int fg, int bg, int ch);
extern float screenaspect;
double xcjul = BIG;
double ycjul = BIG;
extern int hasinverse;
void displays(int x, int y, int fg, int bg, char *str, int len)
{
int i;
for(i=0;i<len; i++)
displayc(x+i*8, y, fg, bg, str[i]);
}
/* circle routines from Dr. Dobbs June 1990 */
int xbase, ybase;
unsigned xAspect, yAspect;
void SetAspect(double aspect)
{
xAspect = 0;
yAspect = 0;
aspect = fabs(aspect);
if (aspect != 1.0)
if (aspect > 1.0)
yAspect = 65536.0 / aspect;
else
xAspect = 65536.0 * aspect;
}
void _fastcall c_putcolor(int x, int y, int color)
{
/* avoid writing outside window */
if ( x < xc || y < yc || x >= xc + xd || y >= yc + yd )
return ;
if(y >= sydots - show_numbers) /* avoid overwriting coords */
return;
if(windows == 2) /* avoid overwriting fractal */
if (0 <= x && x < xdots && 0 <= y && y < ydots)
return;
putcolor(x, y, color);
}
int c_getcolor(int x, int y)
{
/* avoid reading outside window */
if ( x < xc || y < yc || x >= xc + xd || y >= yc + yd )
return 1000;
if(y >= sydots - show_numbers) /* avoid overreading coords */
return 1000;
if(windows == 2) /* avoid overreading fractal */
if (0 <= x && x < xdots && 0 <= y && y < ydots)
return 1000;
return getcolor(x, y);
}
void circleplot(int x, int y, int color)
{
if (xAspect == 0)
if (yAspect == 0)
c_putcolor(x+xbase, y+ybase,color);
else
c_putcolor(x+xbase, (short)(ybase + (((long) y * (long) yAspect) >> 16)),color);
else
c_putcolor((int)(xbase + (((long) x * (long) xAspect) >> 16)), y+ybase, color);
}
void plot8(int x, int y, int color)
{
circleplot(x,y,color);
circleplot(-x,y,color);
circleplot(x,-y,color);
circleplot(-x,-y,color);
circleplot(y,x,color);
circleplot(-y,x,color);
circleplot(y,-x,color);
circleplot(-y,-x,color);
}
void circle(int radius, int color)
{
int x,y,sum;
x = 0;
y = radius << 1;
sum = 0;
while (x <= y)
{
if ( !(x & 1) ) /* plot if x is even */
plot8( x >> 1, (y+1) >> 1, color);
sum += (x << 1) + 1;
x++;
if (sum > 0)
{
sum -= (y << 1) - 1;
y--;
}
}
}
/*
* MIIM section:
*
* Global variables and service functions used for computing
* MIIM Julias will be grouped here (and shared by code in LORENZ.C)
*
*/
long ListFront, ListBack, ListSize; /* head, tail, size of MIIM Queue */
long lsize, lmax; /* how many in queue (now, ever) */
int maxhits = 1;
int OKtoMIIM;
int SecretExperimentalMode;
float luckyx = 0, luckyy = 0;
extern int debugflag;
extern int bitshift; /* bit shift for fudge */
extern long fudge; /* fudge factor (2**n) */
long lsqrt(long f)
{
int N;
unsigned long y0, z;
static long a=0, b=0, c=0; /* constant factors */
if (f == 0)
return f;
if (f < 0)
return 0;
if (a==0) /* one-time compute consts */
{
a = fudge * .4